package com.demoworld;

import org.junit.Assert;
import org.junit.Test;

/**
 * Created by francis on 2017/6/14.
 * list的操作 举例
 */
public class ListTest {
    private String key = "white-tiger-list";
    private String value = "white-tiger";

    //添加 数据到 redis list中，
    @Test
    public void addAndGetFromList() {
        for (int i = 0; i <= 10; i++) {
            CacheHelper.INSTANCE.lpush(key, value + i);
        }

        for (int i = 0; i <= 10; i++) {
            System.out.println(CacheHelper.INSTANCE.lpop(key));//从list中获取并删除一个元素， 注意下 lpush 和  lpop 元素的顺序
        }
    }

    //获取一个list 的长度
    @Test
    public void getLengthOfList() {
        CacheHelper.INSTANCE.delete(key);
        for (int i = 0; i <= 100; i++) {
            CacheHelper.INSTANCE.lpush(key, value + i);
        }
        System.out.println(CacheHelper.INSTANCE.llen(key));
    }
}
